package com.zpb.portal.controller;

import com.zpb.framework.domain.vo.LoginVo;
import com.zpb.framework.exception.SystemException;
import com.zpb.framework.domain.ApiResult;
import com.zpb.framework.domain.enums.ResultCodeEnum;
import com.zpb.portal.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/10
 */
@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;
    @PostMapping("/login")
    public ApiResult<Map<String,Object>> login(@RequestBody LoginVo user) {
        if (!StringUtils.hasText(user.getUsername())){
            throw new SystemException(ResultCodeEnum.NO_USERNAME);
        }
        if (!StringUtils.hasText(user.getPassword())){
            throw new SystemException(ResultCodeEnum.NO_PASSWORD);
        }
        return loginService.login(user);
    }
    @RequestMapping("/logout")
    public ApiResult logout() {
        return loginService.logout();
    }
}
